class MyQueue:
    def __init__(self):
        self.items=[]
    def push(self,x):
        self.items.append(x)
    def pop(self):
        return self.items.pop(0)
    def size(self):
        return len(self.items)
    def show(self):
        ls=[]
        for item in self.items:
            ls.append(str(item))
        return ' '.join(ls)

n=int(input())
q=MyQueue()
for i in range(n):
    choic=input()
    if len(choic)>1:
        a,item=choic.split(' ')
        if a=='1':
            q.push(item)
    if choic=='2':
        if len(q.items)==0:
            print("Invalid")
        else:
            print(q.pop())
    if choic=='3':
        print(q.size())
    if choic=='4':
        print(q.show())